package app.base.commons;

public class Constants {
	
	public static final String CHARSET_ENCODING_UTF8 = "UTF-8";
	public static final String CHARSET_ENCODING_GB2312 = "GB2312";
	public static final String CHARSET_ENCODING_DEFAULT = CHARSET_ENCODING_UTF8;

	// Carriage Return 13 \r
	// New Line 10 \n
	public static final String UNIX_TERMINATORS = "\n";
	public static final String DOS_TERMINATORS = "\r\n";
	public static final String MAC_TERMINATORS = "\r";
	
	public static final String DEFAULT_CONTENT_TYPE = "text/html;charset=UTF-8";
	
	public static final String PROTOCALS_HTTP = "http://";
	public static final String PROTOCALS_HTTPS = "https://";	
	
	//BEGIN	
	public static String SERVLET_CONTEXT_PATH = null;
	public static String SERVLET_CONTEXT_REAL_PATH = null;
	public static String VELOCITY_PROPERTIES_FILENAME  = null;
	
	public static String VELOCITY_VM_PATH = null;

	public static String APP_DOMAIN_NAME = null;
	
	//
	public static boolean __CLASS_CONSTANTS_INIT_BY_HTTPSERVLETREQUEST = false;
	public static void initByHttpServletRequest(javax.servlet.http.HttpServletRequest request) {
		if (!__CLASS_CONSTANTS_INIT_BY_HTTPSERVLETREQUEST) {	//special init the Constants.
			__CLASS_CONSTANTS_INIT_BY_HTTPSERVLETREQUEST = true;
		
			Constants.SERVLET_CONTEXT_PATH = request.getContextPath();
			Constants.VELOCITY_VM_PATH = Constants.SERVLET_CONTEXT_PATH + "/vm";
			
			Constants.APP_DOMAIN_NAME = Constants.PROTOCALS_HTTP 
					+ request.getServerName() + ":" + request.getServerPort() 
					+ Constants.SERVLET_CONTEXT_PATH;
			
			Constants.SERVLET_CONTEXT_REAL_PATH = request.getSession().getServletContext().getRealPath("/");
			Constants.VELOCITY_PROPERTIES_FILENAME  = Constants.SERVLET_CONTEXT_REAL_PATH + "WEB-INF/velocity.properties";
			
			//
		}		
	}
	//END
	
	//
	public static final String DB_MYSQL_CONTEXT_LOOKUP_NAME = "java:comp/env/jdbc/mysql/eshop";
	public static final String DB_CONTEXT_LOOKUP_NAME = DB_MYSQL_CONTEXT_LOOKUP_NAME;

	//
	//org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader = \WEB-INF\classes
	//VELOCITY_TEMPLATES_PATH ="\WEB-INF\vm";
	public static final String VELOCITY_TEMPLATES_PATH ="../../vm";
	
	public static final String APP_MODULES_PATH = "../../modules";

	public static final String VELOCITY_TEMPLATES_THEMES_PATH = VELOCITY_TEMPLATES_PATH + "/themes";
	public static final String VELOCITY_TEMPLATES_THEMES_PATH_DEFAULT = VELOCITY_TEMPLATES_PATH + "/themes/default";
	
}
